﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Lavanderia.BL;
using Lavanderia.Entities;
using Microsoft.Practices.Unity;

namespace Lavanderia.UI
{
    public partial class FrmMttoHotel : Form
    {
        [Dependency]
        public IHotelBL hotelBL { get; set; }

        private bool isNew;
        public FrmMttoHotel()
        {
            InitializeComponent();
            this.BuilUp();
        }

        public void NuevoHotel()
        {
            isNew = true;
            hOTELBindingSource.AddNew();
        }

        public HOTEL _Hotel { get; set; }
        public void EditarHotel()
        {
            isNew = false;
            hOTELBindingSource.DataSource = _Hotel;
        }

        private void btnGuardar_Click(object sender, EventArgs e)
        {
            var hotel = hOTELBindingSource.Current as HOTEL;

            var msg = "ERROR";

            if (hotel!=null)
            {
                if (isNew)
                {
                    try
                    {
                        hotel.NombreHotel = nombreHotelTextBox.Text.ToUpper();
                        hotel.DireccionHotel = direccionHotelTextBox.Text.ToUpper();
                        hotel.TelefonoHotel = telefonoHotelTextBox.Text.ToUpper();
                        hotelBL.AddHotel(hotel);
                        MessageBox.Show("Registro Correcto", "Registro",
                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Close();
                    }
                    catch (Exception ex)
                    {
                        msg = ex.Message;
                        MessageBox.Show(msg, "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                if(isNew == false)
                {
                    try
                    {
                        hotel.NombreHotel = nombreHotelTextBox.Text.ToUpper();
                        hotel.DireccionHotel = direccionHotelTextBox.Text.ToUpper();
                        hotel.TelefonoHotel = telefonoHotelTextBox.Text.ToUpper();
                        hotelBL.UpdateHotel(hotel);
                        MessageBox.Show("Modificación Correcta", "Registro",
                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Close();

                    }
                    catch (Exception ex)
                    {
                        msg = ex.Message;
                        MessageBox.Show(msg, "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
        }
    }
}
